﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using My.Core.Model;

namespace mycoretest.Controllers
{
    [Route("[controller]/[action]")]
    public class HomeController : Controller
    {
        public MyDbContext _MyDbContext;
        ILogger<HomeController> logger;
        public HomeController(MyDbContext myDbContext, ILogger<HomeController> logger)
        {
            this.logger = logger;
            this._MyDbContext = myDbContext;


        }
        // GET: Default
        [HttpGet]
        public ActionResult Index()
        {
            logger.LogInformation("1222222222222222222222222222222222222222");
            var service= HttpContext.RequestServices .GetService(typeof(IServiceProvider))  as IServiceProvider;
            var db =  service.GetService(typeof(MyDbContext));
           
          
            //需要注意的是，使用ServiceLocator.Instance.GetService<T>(); ，只能获取AddTransient和AddSingleton注入的对象，而不能获取AddScoped（请求生命周期内唯一）注入的对象，不是不能获取，而是获取的和构造函数获取的不是相同对象，也就是说获取的对象没有共享，使用场景比如IUnitOfWork。
            return View();
        }

        // GET: Default/Details/5
        [HttpGet]
        public ActionResult Details(int id)
        {
            return View();
        }

       
    }
}